import PlayerFrame from './player-frame.vue';

export default {
  inheritAttrs: false,
  components: {
    PlayerFrame,
  },
  props: {
    dataList: { type: Array, default: () => [] },
    dataSource: { type: Object, default: () => ({}) },
    cameraCode: { type: String, default: '' },
    isPlayback: { type: Boolean, default: false },
    isFullMode: { type: Boolean, default: undefined },
  },
  data() {
    return {
      videoOption: { cameraCode: this.cameraCode },
    };
  },
  computed: {
    fullMode() {
      let isFullMode = this.isFullMode;
      if (isFullMode === undefined) {
        /* 回放模式下默认开启完整模式 */
        isFullMode = this.isPlayback === true;
      }
      return isFullMode;
    },
  },
  created() {
    this.$watch(
      () => this.videoOption,
      function () {
        this.onVideoOptionChange();
      },
      { immediate: this.isPlayback !== true, deep: true }
    );
  },
  methods: {
    onVideoOptionChange() {},
    onVideoSelect(value) {
      this.$refs.PlayerFrame.setSelectValue(value);
    },
    onVideoClose(value) {
      this.$refs.PlayerFrame.delSelectValue(value);
    },
    renderTemplate(children) {
      return this.fullMode === true ? (
        <PlayerFrame
          ref="PlayerFrame"
          v-model={this.videoOption}
          dataSource={this.dataSource}
          isPlayback={this.isPlayback}
        >
          {children()}
        </PlayerFrame>
      ) : (
        children()
      );
    },
  },
};
